package net.pingfang.devicelock;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import net.pingfang.devicelock.util.ReadTooUtil;


@Slf4j
public class NettyClientHandler extends SimpleChannelInboundHandler<Object> {

    /*
    *
    * 报文以0x7b开头 在中间11位判断是否为
    * 0x42 施封响应
    * 0x44 解封响应
    * 0x46 验封响应
    * 0x48 解除警报
    * default
    * */

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
        if(msg != null){
            String result = ReadTooUtil.NetRecvOnePack(msg);
            log.info("应答数据:{}", result);

            /*
            * 将16进制的字符串转为byte[]
            * */
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.error("Netty error", cause);
        ctx.close();
    }

}
